cap log close

global path = "****"

local name= "arms_collapse"
local date = "050520"
global logname = "$path/`name'_`date'.log"

clear
set more off
set matsize 11000
cd "$path"
log using "$logname", replace

use "$path/Data/penalty_sample.dta", clear

replace age_2017=0 if age_2017<0

merge m:1 state_num using "Data/state_cov_effect_050520.dta", nogen

gen cov2016_11 = (covered2016 - any_dec == 11)

gen age_45_64 = age_2017 < 65 & age_2017 >= 45

*define treatment arms
gen early_no_sp = (early == 1 & spanish == 0)
gen early_sp = (early == 1 & spanish == 1)
gen nonpersonalize_no_sp = (nonpersonalize == 1 & spanish == 0)
gen nonpersonalize_sp = (nonpersonalize == 1 & spanish == 1)
gen exemption_info_no_sp = (exemption_info == 1 & spanish == 0)
gen exemption_info_sp = (exemption_info == 1 & spanish == 1)
gen base_no_sp = (base == 1 & spanish == 0)
gen base_sp = (base == 1 & spanish == 1)

drop if age_2017 > 64	

collapse (count) dep_tin (mean) any_covered2017 (mean) any_covered1718 ///
		  (mean) covered2017 (mean) covered1718 (mean) dead1718, ///
		  by(cov2016_11 age_45_64 male above_med_cov_effect ///
			 base_no_sp early_no_sp nonpersonalize_no_sp exemption_info_no_sp  ///
			 base_sp early_sp nonpersonalize_sp exemption_info_sp)

save "$path/`name'_`date'.dta", replace
